Inside Macintosh: Sound

| Previous | Chapter contents | Chapter top | Section top | Next |

Sending Commands to a Sound Channel

Once a sound channel is opened, you can send commands to that channel by issuing requests with the SndDoCommand and SndDoImmediate functions.

The section "Sound Command Numbers" lists the sound commands that you can send using SndDoCommand , SndDoImmediate , or (in several cases) SndControl .

SndDoCommand

You can queue a command in a sound channel by calling the SndDoCommand function.

FUNCTION SndDoCommand (chan: SndChannelPtr; cmd: SndCommand;
                                         noWait: Boolean): OSErr;
chan
A pointer to a valid sound channel.
cmd
A sound command to be sent to the channel specified in the chan parameter.
noWait
A flag indicating whether the Sound Manager should wait for a free space in a full queue ( FALSE ) or whether it should return immediately with a queueFull result code if the queue is full ( TRUE ).

DESCRIPTION

The SndDoCommand function sends the sound command specified in the cmd parameter to the end of the command queue of the channel specified in the chan parameter.

The noWait parameter has meaning only if a sound channel's queue of sound commands is full. If the noWait parameter is set to FALSE and the queue is full, the Sound Manager waits until there is space to add the command, thus preventing your application from doing other processing. If noWait is set to TRUE and the queue is full, the Sound Manager does not send the command and returns the queueFull result code.

SPECIAL CONSIDERATIONS

Whether SndDoCommand moves memory depends on the particular sound command you're sending it. Most of the available sound commands do not cause SndDoCommand to move memory and can therefore be issued at interrupt time. Moreover, you can sometimes safely send commands at interrupt time that would otherwise cause memory to move if you've previously issued the soundCmd sound command to preconfigure the channel at noninterrupt time.

RESULT CODES

noErr

0

No error

queueFull

-203

No room in the queue

badChannel

-205

Channel is corrupt or unusable

SEE ALSO

For an example of a routine that uses the SndDoCommand function, see Listing 1-25 .

SndDoImmediate

You can use the SndDoImmediate function to place a sound command in front of a sound channel's command queue.

FUNCTION SndDoImmediate (chan: SndChannelPtr; cmd: SndCommand):
                                         OSErr;
chan
A pointer to a sound channel.
cmd
A sound command to be sent to the channel specified in the chan  parameter.

DESCRIPTION

The SndDoImmediate function operates much like SndDoCommand , except that it bypasses the existing command queue of the sound channel and sends the specified command directly to the Sound Manager for immediate processing. This routine also overrides any waitCmd , pauseCmd , or syncCmd commands that might have already been processed. However, other commands already received by the Sound Manager will not be interrupted by the SndDoImmediate function (although a quietCmd command sent via SndDoImmediate will quiet a sound already playing).

SPECIAL CONSIDERATIONS

Whether SndDoImmediate moves memory depends on the particular sound command you're sending it. Most of the available sound commands do not cause SndDoImmediate to move memory and can therefore be issued at interrupt time. Moreover, you can sometimes safely send commands at interrupt time that would otherwise cause memory to move if you've previously issued the soundCmd sound command to preconfigure the channel at noninterrupt time.

RESULT CODES

noErr

0

No error

badChannel

-205

Channel is corrupt or unusable

SEE ALSO

For an example of a routine that uses the SndDoImmediate function, see Listing 1-14 .


© 1998 Apple Computer, Inc.

| Previous | Chapter contents | Chapter top | Section top | Next |